/**
 * Created by Richard Radlherr.
 * Date: 14.06.2006 22:52
 */

using System;
using TagTool.Core;

namespace TagTool.Nodes.Math
{
	public class And : BaseNode
	{
		private InputSlot slotA;
		private InputSlot slotB;
		private OutputSlot slotC;
 
		public And() : base()
		{
			Name = "And";
			slotA = new InputSlot(this, "A", false);
			slotB = new InputSlot(this, "B", false);
			slotC = new OutputSlot(this, "C", typeof(bool));
			slotC.Value = false;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotA
		{
			get { return slotA; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotB
		{
			get { return slotB; }
		}

		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot SlotC
		{
			get { return slotC; }
		}

		public override void Update(Object sender)
		{
			slotC.Value = (bool)slotA.Value && (bool)slotB.Value;
		}
	}
	
	public class Or : BaseNode
	{
		private InputSlot slotA;
		private InputSlot slotB;
		private OutputSlot slotC;
  
		public Or() : base()
		{
			Name = "Or";
			slotA = new InputSlot(this, "A", false);
			slotB = new InputSlot(this, "B", false);
			slotC = new OutputSlot(this, "C", typeof(bool));
			slotC.Value = false;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotA
		{
			get { return slotA; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotB
		{
			get { return slotB; }
		}

		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot SlotC
		{
			get { return slotC; }
		}

		public override void Update(Object sender)
		{
			slotC.Value = (bool)slotA.Value || (bool)slotB.Value;
		}
	}

    public class Nand : BaseNode
    {
        private InputSlot slotA;
        private InputSlot slotB;
        private OutputSlot slotC;

        public Nand()
            : base()
        {
            Name = "Nand";
            slotA = new InputSlot(this, "A", false);
            slotB = new InputSlot(this, "B", false);
            slotC = new OutputSlot(this, "C", typeof(bool));
            slotC.Value = false;
        }

        [NodeAttribute(SlotType.Input, Show = true)]
        public InputSlot SlotA
        {
            get { return slotA; }
        }

        [NodeAttribute(SlotType.Input, Show = true)]
        public InputSlot SlotB
        {
            get { return slotB; }
        }

        [NodeAttribute(SlotType.Output, Show = true)]
        public OutputSlot SlotC
        {
            get { return slotC; }
        }

        public override void Update(Object sender)
        {
            slotC.Value = !((bool)slotA.Value && (bool)slotB.Value);
        }
    }

    public class Xor : BaseNode
    {
        private InputSlot slotA;
        private InputSlot slotB;
        private OutputSlot slotC;

        public Xor()
            : base()
        {
            Name = "Xor";
            slotA = new InputSlot(this, "A", false);
            slotB = new InputSlot(this, "B", false);
            slotC = new OutputSlot(this, "C", typeof(bool));
            slotC.Value = false;
        }

        [NodeAttribute(SlotType.Input, Show = true)]
        public InputSlot SlotA
        {
            get { return slotA; }
        }

        [NodeAttribute(SlotType.Input, Show = true)]
        public InputSlot SlotB
        {
            get { return slotB; }
        }

        [NodeAttribute(SlotType.Output, Show = true)]
        public OutputSlot SlotC
        {
            get { return slotC; }
        }

        public override void Update(Object sender)
        {
            slotC.Value = ((bool)slotA.Value ^ (bool)slotB.Value);
        }
    }

	public class Not : BaseNode
	{
		private InputSlot slotA;
		private OutputSlot slotB;
  
		public Not() : base()
		{
			Name = "Not";
			slotA = new InputSlot(this, "A", false);
			slotB = new OutputSlot(this, "B", typeof(bool));
			slotB.Value = true;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotA
		{
			get { return slotA; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot SlotB
		{
			get { return slotB; }
		}

		public override void Update(Object sender)
		{
			slotB.Value = !((bool)slotA.Value);
		}

	}
}
